package com.mhs.mainform;

import com.mhs.rssfeed.RSSFeeder;
import com.mhs.tracuu.TraCuu;

import com.mhs.dataclassification.Classification;
import com.mhs.hotcall.HotCall;
import com.mhs.map.GetHospitalNear;
import com.mhs.mhs_gui.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

public class MainformActivity extends Activity {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainform);
		startService(new Intent(MainformActivity.this, com.mhs.sync.ListenSignalSync.class));
	}

	@Override
	protected void onStart() {
		super.onStart();	
	}

	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.img_tintuc:
			Intent rssFeedIntent = new Intent(this, RSSFeeder.class);
			startActivity(rssFeedIntent);
			break;
		case R.id.img_tracuu:
			Intent tracuuIntent = new Intent(this, TraCuu.class);
			startActivity(tracuuIntent);
			break;
		case R.id.img_bando:
			// truong KHTN: 10.7607344, 106.68351819999998
			double lat = Double.parseDouble("10.844941552209361");
			double lon = Double.parseDouble("106.65114579510646");
			Intent serviceGetHospitalNear = new Intent(MainformActivity.this, GetHospitalNear.class);
			Bundle myData = new Bundle();
			myData.putDouble("latitude", lat);
			myData.putDouble("longitude", lon);
			serviceGetHospitalNear.putExtras(myData);
			startService(serviceGetHospitalNear);
			break;
		case R.id.btn_hotcall:
			Intent hotCallIntent = new Intent(this, HotCall.class);
			startActivity(hotCallIntent);
			break;
		case R.id.btn_setting:
			Intent settingIntent = new Intent(this, Classification.class);
			startActivity(settingIntent);
			break;
		case R.id.btn_exit:
			((ImageButton) findViewById(R.id.btn_exit))
					.setBackgroundResource(R.drawable.exit_onclick2);
			System.exit(0);
			break;
		}
	}

	public void ShowDialog(String message, String title) {
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setTitle(title);
		builder.setMessage(message);
		builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
			}
		});
		builder.show();
	}

	@Override
	protected void onPause() {
		super.onPause();	
	}

	@Override
	protected void onResume() {
		super.onResume();
		startService(new Intent(MainformActivity.this, com.mhs.sync.ListenSignalSync.class));
	}
}